<template>
    <div class="loginbody">
      <div class="logindata">
        <div class="logintext">
          <h2>学生登录</h2>
        </div>
        <div class="formdata">
          <el-form ref="form" :model="form" :rules="rules">
            <el-form-item prop="userId">
              <el-input
                v-model="form.userId"
                clearable
                placeholder="请输入账号"
              ></el-input>
            </el-form-item>
            <el-form-item prop="passwd">
              <el-input
                v-model="form.passwd"
                clearable
                placeholder="请输入密码"
                show-password
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="tool">
         
        </div>
        <div class="butt">
          <el-button type="primary" @click="login('form')"
          :plain="true">登录</el-button
          >
         
        </div>
      </div>
    </div>
  </template>
  
  <script>
  import request from '../utils/request';
  
  
  
  export default {
    name: "login",
    data() {
      return {
        form: {
          userId: "",
          passwd: "",
        },
        
        
        checked: true,
        rules: {
          userId: [
            { required: true, message: "请输入账户", trigger: "blur" },
            { min:  10 ,max: 10, message: "请输入正确的账户", trigger: "blur" },
          ],
          passwd: [
            { required: true, message: "请输入密码", trigger: "blur" },
            { min: 1, message: "密码不能为空", trigger: "blur" },
          ],
        },
      };
    },
 
    methods: {
      login(formName){
        this.form.userRole = 2
        this.$refs[formName].validate((valid) => {
          if(valid){
            request.post("/Admin/loginn",this.form).then(res =>{
           let role = res.data.role
          if(res.data.code === "000"){
             this.$message({
              message: res.data.msg,
              type: 'success'
             }),
             localStorage.setItem('token',res.data.token),
             this.$router.push("/student")
          }else{
            this.$message.error({
              
              message: res.data.msg,
              
             })
          }
        })
          }else{
            return false;
          }
        })
  
      },
      
  
      register() {},
    },
  };
  </script>
  <!--测试-->
  <style scoped>
  .loginbody {
    width: 100%;
    height: 100%;
    min-width: 1000px;
    background-image: url("https://img1.baidu.com/it/u=1781547386,2483569991&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500");
    background-size: 100% 100%;
    background-position: center center;
    overflow: auto;
    background-repeat: no-repeat;
    position: fixed;
    line-height: 100%;
    padding-top: 150px;
  }
  
  .logintext {
    margin-bottom: 20px;
    line-height: 50px;
    text-align: center;
    font-size: 30px;
    font-weight: bolder;
    color: white;
    text-shadow: 2px 2px 4px #000000;
  }
  
  .logindata {
    width: 400px;
    height: 300px;
    transform: translate(-50%);
    margin-left: 50%;
  }
  
  .tool {
    display: flex;
    justify-content: space-between;
    color: #606266;
  }
  
  .butt {
    margin-top: 10px;
    text-align: center;
  }
  
  .shou {
    cursor: pointer;
    color: #606266;
  }
  
  
  </style>
  